package io.yizoo.core.message;

import io.elm.core.Ctor;
import io.yizoo.system.entity.sys_user_third;
import io.yizoo.system.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class MessageFactory {
    @Autowired
    private Map<String, MessageService> messageServiceMap;
    @Autowired
    public io.elm.core.Ctor Ctor;

    /**
     * 根据发送人获取一个实例
     * @param sendUserId 发送人
     * @return
     */
    public MessageService getInstance(String sendUserId) {
        if (StringUtil.isEmpty(sendUserId)) {
            throw new RuntimeException("请输入发送人员");
        }
        sys_user_third sys_user_third = Ctor.HMapper.GetSingle(sys_user_third.class,
                Ctor.DMaker().Selector
                        .From(sys_user_third.class)
                        .putFactorItem("id", sendUserId)
                        .IsWhere("and user_id = #{id}",sendUserId)
                        .Limit("limit 1")
                        .GetFactor());
        if (sys_user_third == null) {
            throw new RuntimeException("发送人员不存在");
        }
        return messageServiceMap.get(sys_user_third.getThird_type());
    }
}
